home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 870 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.7 KB  |  59 lines

  1. Path: cs.mu.OZ.AU!bounce-back
  2. From: sunny@libra.math.tau.ac.il (Marueli Sunny)
  3. Newsgroups: comp.std.c++
  4. Subject: Suggestion to the C++ standard
  5. Date: 27 Mar 96 10:16:45 GMT
  6. Organization: School of Math & CS - Tel Aviv University , Tel Aviv , ISRAEL.
  7. Approved: fjh@cs.mu.oz.au
  8. Message-ID: <4jatnm$s9b@post.tau.ac.il>
  9. NNTP-Posting-Host: munta.cs.mu.oz.au
  10. X-Original-Date: 27 Mar 1996 08:20:06 GMT
  11. X-Newsreader: TIN [version 1.2 PL2]
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBFAgUBMVkVmeEDnX0m9pzZAQEaUQF/TLrMWHDsUcihK8Qgk+oHmoXNbV0SpBcu
  14.     SwLiyrWyOSFrMrEpsbO3olNfB5rQaTNE
  15.     =e0ru
  16. Originator: fjh@munta.cs.mu.OZ.AU
  17.  
  18. Hello.
  19.  
  20. C++ is an OO language, and of course supports encapsulation.
  21. Problem is - there is no standard way to add access methods.
  22. For example:
  23. class foo
  24. {
  25. public:
  26.     SetMember( Type aMember );
  27.     Type Member( );
  28. private:
  29.     Type Member;
  30. };
  31.  
  32. Now, this code is reasonable, but it could be better:
  33. [ I really don't know where I'm stealing this syntax. Sorry, anyway ]
  34.  
  35. class foo
  36. {
  37. private:
  38.     Type Member : read GetMember, write SetMember;
  39. };
  40.  
  41. and then you can do something like:
  42. foo x;
  43. x.Member = 5; // Calls SetMember()
  44. cout << x.Member; // Calls GetMember()
  45.  
  46.  
  47. I think this kind of code is much more elegant, and forces the use of
  48. access methods, which isn't bad by itself.
  49.  
  50. ------------
  51.  
  52.    Sunny
  53. ---
  54. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  55. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  56. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  57. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  58. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  59.